package com.jgsu.farm.service.impl;

import com.jgsu.farm.entity.User;
import com.jgsu.farm.mapper.sql.UserMapperSql;
import com.jgsu.farm.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional(rollbackFor = RuntimeException.class)
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapperSql userMapperSql;

    /**
     * 根据删除数据
     * */
    @Override
    public int deleteUserByID(Integer userid) {
        return userMapperSql.deleteUserByID(userid);
    }

    @Override
    public Integer modifyExpertMsg(Integer userid, String password, Integer role, String name, String nickname,
                                   String phone, String email, Integer address, String postcode, String photo,
                                   String introduction, Integer state) {
        Integer modifyExpertMsg = userMapperSql.modifyExpertMsg(userid, password, role, name, nickname, phone, email,
                address, postcode, photo, introduction, state);
        return modifyExpertMsg;
    }

    /**
     * 分页查询专家用户信息，并且可以通过state筛选是否通过审核
     * */
    @Override
    public PageInfo<User> FindExpertListByState(Integer role, Integer state, int page, int pagesize) {
        PageHelper.startPage(page, pagesize);
        List<User> users = userMapperSql.selectUserByState(role,state);
        PageInfo<User> pageInfoUserList = new PageInfo<User>(users);
        return pageInfoUserList;
    }
}
